﻿using JRC.LCA.ILCD.SDK;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using lca.jrc.it.ILCD.Contact;
using System.Collections.Generic;
using lca.jrc.it.ILCD.FlowProperty;
using lca.jrc.it.ILCD.Flow;
using lca.jrc.it.ILCD.Process;
using lca.jrc.it.ILCD.Source;
using lca.jrc.it.ILCD.UnitGroup;
using lca.jrc.it.ILCD.Categories;
using lca.jrc.it.ILCD.Locations;
using System;

namespace ILCD_Test
{
    
    
    /// <summary>
    ///This is a test class for ELCD2ReaderTest and is intended
    ///to contain all ELCD2ReaderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ELCD2ReaderTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        ELCD2Reader target;
        [TestInitialize()]
        public void MyTestInitialize()
        {
            target = new ELCD2Reader(@"D:\STUDY\Standards\ELCD2");
        }
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for GetFlow
        ///</summary>
        [TestMethod()]
        public void GetFlowTest()
        {
            //test first flow in flows directory
            string uuid = "0d7a3ad0-6556-11dd-ad8b-0800200c9a66";
            string actual;
            actual = target.GetFlow(new Guid(uuid)).flowInformation.dataSetInformation.UUID.TypedValue;
            Assert.AreEqual(uuid, actual);
        }

        /// <summary>
        ///A test for ILCDLocations
        ///</summary>
        [TestMethod()]
        public void ILCDLocationsTest()
        {
            foreach (var item in target.ILCDLocations.location)
            {
                Assert.IsNotNull(item.value);
            }
        }

        /// <summary>
        ///A test for ILCDFlowCategorization
        ///</summary>
        [TestMethod()]
        public void ILCDFlowCategorizationTest()
        {
            //test first flowcategory
            Assert.AreEqual(target.ILCDFlowCategorization.categories[0].dataType, "Flow");
            Assert.AreEqual(target.ILCDFlowCategorization.categories[0].category[0].name, "Emissions");
            Assert.AreEqual(target.ILCDFlowCategorization.categories[0].category[0].category[0].name, "Emissions to water");
            Assert.AreEqual(target.ILCDFlowCategorization.categories[0].category[0].category[0].category[0].name, "Emissions to fresh water");
        }

        /// <summary>
        ///A test for ILCDClassification
        ///</summary>
        [TestMethod()]
        public void ILCDClassificationTest()
        {
            //test first category
            Assert.AreEqual(target.ILCDClassification.categories[0].dataType, "Process");
            Assert.AreEqual(target.ILCDClassification.categories[0].category[0].name, "Energy carriers and technologies");
            Assert.AreEqual(target.ILCDClassification.categories[0].category[0].category[0].name, "Energetic raw materials");
        }

        /// <summary>
        ///A test for AllUnitGroup
        ///</summary>
        [TestMethod()]
        public void AllUnitGroupTest()
        {
            foreach (var item in target.AllUnitGroup)
            {
                Assert.IsNotNull(item.unitGroupInformation.dataSetInformation.name);
            }
        }

        /// <summary>
        ///A test for AllSources
        ///</summary>
        [TestMethod()]
        public void AllSourcesTest()
        {
            foreach (var item in target.AllSources)
            {
                Assert.IsNotNull(item.sourceInformation.dataSetInformation.shortName);
            }
        }

        /// <summary>
        ///A test for AllProcesses
        ///</summary>
        [TestMethod()]
        public void AllProcessesTest()
        {
            foreach (var item in target.AllProcesses)
            {
                Assert.IsNotNull(item.processInformation.dataSetInformation.name);
            }
        }

        /// <summary>
        ///A test for AllFlows
        ///</summary>
        [TestMethod()]
        public void AllFlowsTest()
        {
            foreach (var item in target.AllFlows)
            {
                Assert.IsNotNull(item.flowInformation.dataSetInformation.name);
            }
        }

        /// <summary>
        ///A test for AllFlowProperties
        ///</summary>
        [TestMethod()]
        public void AllFlowPropertiesTest()
        {
            foreach (var item in target.AllFlowProperties)
            {
                Assert.IsNotNull(item.flowPropertiesInformation.dataSetInformation.name);
            }
        }

        /// <summary>
        ///A test for AllContacts
        ///</summary>
        [TestMethod()]
        public void AllContactsTest()
        {
            foreach (var item in target.AllContacts)
            {
                Assert.IsNotNull(item.contactInformation.dataSetInformation.name);
            }
        }
    }
}
